/**
 * 
 */
package Controller;

import java.awt.Desktop;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Logger;

import javax.swing.JLabel;

/**
 * @author enzo
 *
 */
public class LinkListener implements MouseListener {

	AgendaManager agenda;
	/**
	 * @param a
	 */
	public LinkListener(AgendaManager a)
	{
		agenda=a;
	}
	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

        
        try {
        	if(e.getSource()==agenda.getMf().getDisplay().getUrl()) agenda.openWebsite();
        	else   agenda.sendMailto((JLabel)e.getSource());
        } catch (URISyntaxException ex) {
           ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
	 */
	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

		JLabel link=(JLabel)e.getSource();
		String plainText = link.getText().replaceAll("\\<.*?\\>", "");
		link.setText("<html><u>"+plainText+"</u></html>");
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		JLabel link=(JLabel)e.getSource();
		String plainText = link.getText().replaceAll("\\<.*?\\>", "");
		link.setText("<html>"+plainText+"</html>");
	}

}
